<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<style type="text/css">
    li.no_product {
        /* margin: 80px 0; */
        margin: 200px 0px 0px 0px !important;
        text-align: center;
        font-size: 33px;
        width: 100% !important;
        color: red;
    }
</style>

<!-- 显示菜单 -->
<div class="sort-bar">
    <div class="bar-l">
        <!-- 查看方式S -->
        <%--<div class="switch">
            <span class="selected">
                <a title="以方格显示" ecvalue="squares" nc_type="display_mode" class="pm" href="javascript:void(0)">大图</a>
            </span>
            &lt;%&ndash;<span style="border-left:none;">
                <a title="以列表显示" ecvalue="list" nc_type="display_mode" class="lm" href="javascript:void(0)">列表</a>
            </span>&ndash;%&gt;
        </div>--%>
        <!-- 查看方式E -->

        <!-- 排序方式S -->
        <ul class="array">
            <li class="${empty sort?'selected':''}">
                <a href="/render/product/search?id=${cid}&min=${min}&max=${max}&search_key=${search_key}&parent_id=${parent_id}&pc=1&key=${key}" title="默认排序">默认</a>
            </li>
            <li class="${sort=='sale_count'?'selected':''}">
                <a href="/render/product/search?id=${cid}&min=${min}&max=${max}&search_key=${search_key}&parent_id=${parent_id}&pc=1&sort=${sort=='sale_count'?'':'sale_count'}&key=${key}" title="点击按销量从高到低排序">销量</a>
            </li>
            <li class="${sort=='popularity'?'selected':''}">
                <a href="/render/product/search?id=${cid}&min=${min}&max=${max}&search_key=${search_key}&parent_id=${parent_id}&pc=1&sort=${sort=='popularity'?'':'popularity'}&key=${key}" title="点击按人气从高到低排序">人气</a>
            </li>
            <%--<li class="${sort=='credit'?'selected':''}">
                &lt;%&ndash;/render/product/search?id=${id}&parent_id=${parent_id}&sort=credit&key=${key}&ndash;%&gt;
                <a href="javascript:void(0);" title="点击按信用从高到低排序">信用</a>
            </li>--%>

            <li class="${(sort=="price"||sort=="priceInverse")?'selected':''}">
                <%--如果上次的等于这次的，那就反过来。----> 这仅是价格--%>
                <a href="/render/product/search?id=${cid}&min=${min}&max=${max}&search_key=${search_key}&parent_id=${parent_id}&pc=1&sort=${sort=='price'?'priceInverse':'price'}&key=${key}" title="点击按价格从高到低排序">价格</a>
            </li>
        </ul>
        <!-- 排序方式E -->

        <!-- 价格段S -->
        <form action="javascript:void(0);" method="post">
            <div class="prices"><em>¥</em>
                <input type="text" value='${min}' class="w30" name="min" id="min">
                <em>-</em>
                <input type="text" value='${max}' class="w30" name="max" id="max">
                <input type="submit" value="确认" id="search_by_price" onclick="searchByPrice('/render/product/search?id=${cid}&search_key=${search_key}&parent_id=${parent_id}&pc=1&sort=${sort}&key=${key}');">
            </div>
        </form>
        <!-- 价格段E -->
    </div>
</div>
<div class="clear"></div>
<!-- 显示菜单 End -->
<!-- 商品列表 -->
<div class="shop_bd_list_content clearfix">
    <ul>
        <c:if test="${empty pb.beanList}">
            <li class="no_product">对不起，没有对应商品。</li>
        </c:if>
        <c:if test="${!empty pb.beanList}">
            <c:forEach items="${pb.beanList}" var="product">
                <li>
                    <dl>
                        <dt>
                            <a href="/render/product/product_detail?id=${product.id}">
                                <img src="${product.main_image}"/>
                            </a>
                        </dt>
                        <dd class="title">
                            <a href="/render/product/product_detail?id=${product.id}">
                                ${product.name}
                            </a>
                        </dd>
                        <dd class="content">
                            <a href="/render/product/product_detail?id=${product.id}">
                                最近浏览量：${product.popularity}
                            </a>
                        </dd>
                        <dd class="content">
                            <span class="goods_jiage">
                                ￥<strong>${product.price}</strong>
                            </span>
                            <span class="goods_chengjiao">最近成交${product.sale_count}笔</span>
                        </dd>
                    </dl>
                </li>
            </c:forEach>
        </c:if>
    </ul>
</div>

<div class="clear"></div>

<div class="pagination">
    <ul>
        <li>
            <span><a href="/render/product/search?id=${cid}&min=${min}&max=${max}&search_key=${search_key}&parent_id=${parent_id}&pc=1&sort=${sort}&key=${key}">首页</a></span>
        </li>
        <%--上一页 --%>
        <li>
            <c:choose>
                <c:when test="${pb.pc eq 1 }">
                    <span>上一页</span>
                </c:when>
                <c:otherwise>
                    <span><a href="/render/product/search?id=${cid}&min=${min}&max=${max}&search_key=${search_key}&parent_id=${parent_id}&pc=${pb.pc-1}&sort=${sort}&key=${key}">上一页</a></span>
                </c:otherwise>
            </c:choose>
        </li>

        <c:choose>
            <c:when test="${pb.tp <= 6 }">
                <c:set var="begin" value="1"/>
                <c:set var="end" value="${pb.tp }"/>
            </c:when>
            <c:otherwise>
                <c:set var="begin" value="${pb.pc-2 }"/>
                <c:set var="end" value="${pb.pc + 3}"/>
                <c:if test="${begin < 1 }">
                    <c:set var="begin" value="1"/>
                    <c:set var="end" value="6"/>
                </c:if>
                <c:if test="${end > pb.tp }">
                    <c:set var="begin" value="${pb.tp-5 }"/>
                    <c:set var="end" value="${pb.tp }"/>
                </c:if>
            </c:otherwise>
        </c:choose>

        <c:forEach begin="${begin }" end="${end }" var="i">
            <c:choose>
                <c:when test="${i eq pb.pc }">
                    <li><span class="spanBtnSelect">${i}</span></li>
                </c:when>
                <c:otherwise>
                    <li><span><a href="/render/product/search?id=${cid}&min=${min}&max=${max}&search_key=${search_key}&parent_id=${parent_id}&pc=${i}&sort=${sort}&key=${key}" class="aBtn">${i}</a></span></li>
                </c:otherwise>
            </c:choose>
        </c:forEach>

        <c:if test="${end < pb.tp }">
            <span class="spanApostrophe">...</span>
        </c:if>

        <%--下一页 --%>
        <li>
            <c:choose>
                <c:when test="${pb.pc eq pb.tp }">
                    <span>下一页</span>
                </c:when>
                <c:otherwise>
                    <span><a href="/render/product/search?id=${cid}&min=${min}&max=${max}&search_key=${search_key}&parent_id=${parent_id}&pc=${pb.pc+1}&sort=${sort}&key=${key}">下一页</a></span>
                </c:otherwise>
            </c:choose>
        </li>
        <li>
            <c:choose>
                <c:when test="${pb.pc eq pb.tp }">
                    <span>末页</span>
                </c:when>
                <c:otherwise>
                    <span><a href="/render/product/search?id=${cid}&min=${min}&max=${max}&search_key=${search_key}&parent_id=${parent_id}&pc=${pb.tp}&sort=${sort}&key=${key}">末页</a></span>
                </c:otherwise>
            </c:choose>
        </li>
    </ul>
</div>
<a href="/render/cart/buyOne?pid=${product.id}" id="buy-link" style="display:none;"><span id="buy_link_btn"></span></a>
<script type="text/javascript">
    // $("#search_by_price").click()
    function searchByPrice(url) {

        // if ($("#min").val() == null || $("#min").val() == "") {
        //     HFalert({title: "最小范围", type: 'warning', confirmButtonText: '确定'});
        //     return;
        // }
        var add_url=url+"&min="+$("#min").val()+"&max="+$("#max").val();
        $("#buy-link").attr("href",add_url);
        /*click事件直接绑定到<a>标签上，必须绑定到<a> 标签之内的元素上。*/
        $("#buy_link_btn").click();
    }
</script>
<!-- 商品列表 End -->